package com.myprinciple.singleresponsibility;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/4/9 9:46
 */
public class SingleResponsibility2 {

    public static void main(String[] args) {
        RoadVehicle roadVehicle = new RoadVehicle();
        roadVehicle.run("摩托车");
        roadVehicle.run("汽车");

        AirVehicle airVehicle = new AirVehicle();
        airVehicle.run("飞机");
    }
    
}

// 方案2
// 1.遵守了单一职责原则
// 2.但是这样做的改动很大，即将类分解，同时修改客户端
// 3.改进：直接修改Vehicle，改动代码比较少=>3
class RoadVehicle{
    public void run(String vehicle){
        System.out.println(vehicle + "在公路上运行");
    }
}

class AirVehicle{
    public void run(String vehicle){
        System.out.println(vehicle + "在天上上运行");
    }
}

class WaterVehicle{
    public void run(String vehicle){
        System.out.println(vehicle + "在水中上运行");
    }
}